<?xml version="1.0" encoding="UTF-8"?>
<UISpecification name="MatDataSOD" type="UILayout" version="2.0">
	<Event listener="show" type="onShow" />
	<Properties>
		<Property name="sodExtractor" type="SMData">
			<Arg name="extractorType" value="SingleObject"/>
			<Arg name="inputName" value="smInputObject"/>
			<Arg name="viewName" value="Default,Relation,modDetailed"/>
			<Arg name="objectType" value="MatData"/>
		</Property>
		<Property name="modelExtractor" type="SMData">
			<Arg name="extractorType" value="MultipleObject"/>
			<Arg name="inputName" value="smInputObject"/>
			<Arg name="objectType" value="MatData"/>
		</Property>
	</Properties>

	<Binding sourceParam="smInputObject" target="processMapWidget" targetParam="anchor"/>

	<SMBinding sourceParam="sodExtractor" visualizers="processMenu,objectToolBar,createCommentsLink,comments" viewName="Default"/>
	<SMBinding sourceParam="sodExtractor" visualizers="relations" viewName="Relation"/>
	<SMBinding sourceParam="modelExtractor" visualizers="materials" viewName="Relation"/>

	<Widget name="sodMenuBarPanel" type="GridPanel">
		<Arg name="expandWidth" value="false"/>
		<Arg name="expandHeight" value="true"/>
		<Arg name="styleClass" value="TableBorder"/>
		<Widget name="processMenuPanel" type="GridPanel">
			<Arg name="expandWidth" value="false"/>
			<Arg name="columns" value="2"/>
			<Arg name="columnClasses" value="leftSODTitle,left"/>
			<Arg name="styleClass" value="SODTitle"/>
			<Widget name="imageLabelPanel" type="Panel">
				<Arg name="columns" value="2"/>
				<Widget name="iconWidget" type="Image">
					<Arg name="expandWidth" value="false"/>
				</Widget>
				<Widget name="objLabelDecPanel" type="GridPanel">
					<Arg name="expandWidth" value="false"/>
					<Widget name="sodObjectLabelWidget" type="Label">
						<Arg name="expandWidth" value="false"/>
					</Widget>
				</Widget>
			</Widget>
			<Widget name="processMenu" type="SMActionsMenuBar">
				<Arg name="expandWidth" value="false"/>
			</Widget>
		</Widget>
	</Widget>
	<Widget name="objectToolBar" type="SMActionsToolBar">
		<Arg name="expandWidth" value="true"/>
	</Widget>

	<Widget name="dashBoardPanel" type="Panel">
		<Arg name="columns" value="1"/>
		<Arg name="expandWidth" value="true"/>
		<Arg name="expandHeight" value="true"/>
		<Widget name="relationPanel" type="GridPanel">
			<Arg name="columns" value="1"/>
			<Arg name="expandWidth" value="true"/>
			<Arg name="expandHeight" value="true"/>
			<Widget name="relationTabPane" type="TabbedPane">
				<Widget name="detailsTab" type="Tab">
					<Arg name="expandWidth" value="true"/>
					<Arg name="expandHeight" value="true"/>
					<Arg name="title" value="uiWidget.smWidgets.sod.detailsTab.label"/>
					<Widget name="detailspanel" type="GridPanel">
						<Widget name="materialSOD" type="Panel">
							<Arg name="expandWidth" value="true" />
							<Widget name="materials" type="SMMaterials">
								<Arg name="expandWidth" value="true"/>
								<Arg name="expandHeight" value="true"/>
							</Widget>
						</Widget>
					</Widget>
				</Widget>

				<Widget name="assemblyTab" type="Tab">
					<Arg name="expandWidth" value="true"/>
					<Arg name="expandHeight" value="true"/>
					<Arg name="title" value="uiWidget.smWidgets.sod.assemblyTab.label"/>
					<Widget name="assembly" type="MODWTKTable">
						<Arg name="expandWidth" value="true"/>
						<Arg name="expandHeight" value="true"/>
						<Arg name="showMODLink" value="false"/>
						<Arg name="insulateMOD" value="true"/>
						<Arg name="highlightRevisions" value="InActive"/>
					</Widget>
				</Widget>

				<!--              <Widget name="relationsTab" type="Tab">
                  <Arg name="expandWidth" value="true"/>
                  <Arg name="expandHeight" value="true"/>
                  <Arg name="title" value="uiWidget.smWidgets.sod.relationsTab.label"/>
                  <Widget name="relations" type="SMRelations">
                     <Arg name="showRelations" value="onlyTypeConfig"/>
                     <Arg name="view" value="Detailed"/>
                  </Widget>
               </Widget> -->
				<Widget name="revisionTab" type="Tab">
					<Arg name="expandWidth" value="true"/>
					<Arg name="expandHeight" value="true"/>
					<Arg name="title" value="uiWidget.smWidgets.sod.revisionsTab.label"/>
					<Widget name="revisionsTable" type="MODWTKTable">
						<Arg name="expandWidth" value="true"/>
						<Arg name="expandHeight" value="true"/>
						<Arg name="showMODLink" value="false"/>
						<Arg name="insulateMOD" value="true"/>
						<Arg name="highlightRevisions" value="InActive"/>
					</Widget>
				</Widget>
				<Widget name="matModelsTab" type="Tab">
					<Arg name="title" value="CAE Models"/>
					<Widget name="matModelTab" type="com/msc/sdm/app/ModelsTab">
						<Arg name="expandWidth" value="true" />
						<Arg name="expandHeight" value="true" />
					</Widget>
				</Widget>
				<Widget name="testDataTab" type="Tab">
					<Arg name="expandWidth" value="true"/>
					<Arg name="expandHeight" value="true"/>
					<Arg name="title" value="Test Data"/>
					<Widget name="testDataWidget" type="MODWTKTable">
						<Arg name="expandWidth" value="true"/>
						<Arg name="expandHeight" value="true"/>
						<Arg name="showMODLink" value="false"/>
						<Arg name="insulateMOD" value="true"/>
						<Arg name="highlightRevisions" value="InActive"/>
					</Widget>
				</Widget>
				<Widget name="processViewTab" type="Tab">
					<Arg name="title" value="uiWidget.smWidgets.sod.processViewerTab.label"/>
					<Arg name="tooltip" value="uiWidget.smWidgets.sod.processViewerTab.label"/>
					<Arg name="columns" value="1"/>
					<Widget name="processMapWidget" type="SMProcessMapViewer">
					</Widget>
				</Widget>
				<Widget name="commentsTab" type="Tab">
					<Arg name="title" value="uiWidget.smWidgets.sod.comment.title"/>
					<Widget name="commentspanel" type="Panel">
						<Arg name="expandWidth" value="true" />
						<Arg name="expandHeight" value="true" />
						<Widget name="comments" type="SMCommentsTable">
							<Arg name="expandWidth" value="true" />
							<Arg name="expandHeight" value="true" />
							<Arg name="label" value="" />
							<Arg name="commentsHeaderLabel" value="uiWidget.smWidgets.sod.modelCommentHeader.label" />
							<Arg name="showAddDeleteComments" value="true" />
							<Arg name="enableRowSelection" value="true" />
						</Widget>
					</Widget>
				</Widget>
				<Widget name="approvalRequestsTab" type="Tab">
					<Arg name="title" value="Approval Requests"/>
					<Widget name="approvalRequestTab" type="com/msc/sdm/app/ApprovalRequestTab">
						<Arg name="expandWidth" value="true" />
						<Arg name="expandHeight" value="true" />
					</Widget>
				</Widget>

			</Widget>
		</Widget>
	</Widget>
	<Script language="JavaScript">
		<![CDATA[

    function show() {
    
    
    	 var smmaterials = uilayout.getWidget( "materials" ,true );
 
    
          var selectedObjectQuery = uilayout.getValue("smInputObject");
          var selectedObject = selectedObjectQuery.retrieveObjects().get(0);
          var manager = conn.getI18NL10NManager(null);          
          var sodObjectLabelWidget = uilayout.getWidget("sodObjectLabelWidget", true);
          var name = selectedObject.evaluate("name").getString();          
          var label = "";
          if (name != null) {
              label = name + " [ " + manager.getObjectTypeLabel(selectedObject.getObjectType()) + " ]";
          } else {
              label = " [ " + manager.getObjectTypeLabel(selectedObject.getObjectType()) + " ]";
          }
      sodObjectLabelWidget.setValue("label", label);
      setImages();
      
      //Revisions Table
      var revs = uilayout.getWidget("revisionsTable" , true);
	   revs.setInput(selectedObjectQuery.navigate("allRevisions():MatData"));
	   revs.setView("revision");
	   var serviceRegistry = uiContext.getServiceRegistry( );
       var sodUtil = serviceRegistry.getObject( "sodUtil" );
	   var sortDefn = sodUtil.getSortDefinition("editRevisionNumber", false);
	   revs.addSorting(sortDefn);
	   revs.setReadOnly(true);
	   sodUtil.populateApprovalRequests(selectedObject, uilayout);
	   sodUtil.populateMatModelsTab(selectedObject, uilayout);
	   
	   //Assembly Table
	   var caeModelQuery = selectedObjectQuery.navigate("components.component:MatMaterialModel"); 
	   if(!caeModelQuery.matchesAny())
	   {
	   		var query = selectedObjectQuery.navigate("components:MatComponent");
	   		if(!query.matchesAny())
	   		{
	   			var assemblyTabWidget = uilayout.getWidget("assemblyTab" , true);
	   			assemblyTabWidget.setValue( "visibility", java.lang.Boolean.FALSE );
	   		} else {
	   				var assemblyWidget = uilayout.getWidget("assembly" , true);
				   assemblyWidget.setInput(query);
				   assemblyWidget.setView("Default");
				   var assemblySortDefn = sodUtil.getSortDefinition("order", true);
				   assemblyWidget.addSorting(assemblySortDefn);
				   assemblyWidget.setReadOnly(true);		   
		   }
	   } else {
	   		var assemblyTabWidget = uilayout.getWidget("assemblyTab" , true);
		   		var assemblyWidget = uilayout.getWidget("assembly" , true);
			   	assemblyWidget.setInput(caeModelQuery);
			   	assemblyWidget.setView("Default");
			   	assemblyTabWidget.setValue("title", manager.getMsg("uiWidget.smWidgets.sod.caeModelsTab.label"));
	   }
	   
	   //Test Data Table
	   var tdQuery = selectedObjectQuery.navigate("generatedFromModel:MatTest");
	   if(!tdQuery.matchesAny())
	   {
	   		var testDataTab = uilayout.getWidget("testDataTab" , true);
	   		testDataTab.setValue( "visibility", java.lang.Boolean.FALSE );
	   } else {
	   		var testDataW = uilayout.getWidget("testDataWidget" , true);
		   testDataW.setInput(tdQuery);
		   //testDataW.setView("Default");
	   }
	   
	   
	   
//-------------------------------------------------------------

var plmUid = selectedObject.evaluate( "plmUid" ).getString();
if( plmUid != null ){
	var classificationTable = uilayout.getWidget( "Classification_Table" , true );
	if( classificationTable != null ){
		var firstWidget = classificationTable.getWidgetAt( 0 , 1 );
		
	 	//var matName =  selectedObject.evaluate( "name" ).getString();
		var matName = firstWidget.getValue( "value" );
		
		//var appInfoLabel =  uilayout.getContext().getFactory().createWidget( "application_statistical_label" , "Label", uiContext  );
		//appInfoLabel.setLabel( "Part Info");
		//classificationTable.setWidgetAt( 0 , 0 , appInfoLabel );
		
		
		var appInfoLink =  uilayout.getContext().getFactory().createWidget( "application_statistical_link" , "ExternalLink", uiContext  );
		appInfoLink.setLabel( matName );
		appInfoLink.setValue( "Url" , "https://plm.nevint.com/3dspace/common/emxNavigator.jsp?objectId=" + plmUid );
		//classificationTable.setWidgetAt( 0 , 1 , appInfoLink );
		classificationTable.replaceChildWidget( firstWidget , appInfoLink );
		
	}
}
//------------------------------------------------------------
	   
	   
	   
	}    

    function setImages()
        {
            var serviceRegistry = uiContext.getServiceRegistry();
            var smWidgetsUtils = serviceRegistry.getObject("smWidgetsUtils");
            var headerIconPath = smWidgetsUtils.getIconImageForQuery(uilayout.getValue("smInputObject"),32);
            uilayout.getWidget("iconWidget",true).setValue("imageSrcPath",headerIconPath);
        }
        
        function handleRefreshButtonEvent(){
				var materialsWidget = uilayout.getWidget("materials", true);
				materialsWidget.refresh();
							      	 
      	 }

             ]]>
	</Script>

</UISpecification>